<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var time2 = new Date("2021-11-22 8:30");
      function fn() {
        var time1 = new Date();

        var time1stamp = time1.getTime() / 1000;
        var time2stamp = time2.getTime() / 1000;
        var res = parseInt(time2stamp - time1stamp);
        //   console.log(res);
        var day = parseInt(res / 3600 / 24);
        //   console.log(day);
        var hour = parseInt((res / 3600) % 24);
        //   console.log(hour);
        var minute = parseInt((res / 60) % 60);
        //   console.log(minute);
        var second = parseInt(res % 60);
        //   console.log(second);
        var str = `距离周一上课还有${day}天${hour}时${minute}分${second}秒`;
        document.body.innerHTML = str;
      }
      setInterval(function () {
        fn();
      }, 1000);
    </script>
  </body>
</html>
